//
//  SearchStatisticViewController.m
//  CityFire
//
//  Created by garychen on 2017/10/15.
//  Copyright © 2017年 刘养柱. All rights reserved.
//

#import "SearchStatisticViewController.h"
#import "WSDatePickerView.h"
#import "MonitorViewModel.h"
#import "StatisticViewModel.h"
#import "StatisticViewController.h"

@interface SearchStatisticViewController ()
@property (nonatomic, strong) MonitorViewModel *monitorViewModel;
@property (nonatomic, strong) StatisticViewModel *stisticViewModel;
@property (weak, nonatomic) IBOutlet UILabel *startTimeLbl;
@property (nonatomic, strong) NSString *startTime;
@property (nonatomic, strong) NSString *endTime;
@property (weak, nonatomic) IBOutlet UILabel *endTimeLbl;
- (IBAction)searchBtnClick:(UIButton *)sender;
- (IBAction)startDate:(UIButton *)sender;
- (IBAction)endDate:(UIButton *)sender;

@end

@implementation SearchStatisticViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.startTimeLbl.text = [[NSDate date]  stringWithFormat:@"yyyy-MM-dd"];
    self.endTimeLbl.text = [[NSDate date]  stringWithFormat:@"yyyy-MM-dd"];
     self.startTime = [[NSDate date]   stringWithFormat:@"yyyyMMdd"];
     self.endTime = [[NSDate date]   stringWithFormat:@"yyyyMMdd"];
    self.view.backgroundColor = [UIColor colorWithRed:240/255.0 green:240/255.0 blue:240/255.0 alpha:1.0];
    // Do any additional setup after loading the view from its nib.
}

- (void)showTimeSelect:(BOOL)isStart {
    WSDatePickerView *datepicker = [[WSDatePickerView alloc] initWithDateStyle:DateStyleShowYearMonthDay CompleteBlock:^(NSDate *selectDate) {
        
        
        NSString *date = [selectDate stringWithFormat:@"yyyy-MM-dd"];
        NSLog(@"选择的日期：%@",date);
        
        
        if (isStart) {
            self.startTimeLbl.text = date;
            self.startTime = [selectDate stringWithFormat:@"yyyyMMdd"];
           
            //秒
//            self.startTime = [NSString stringWithFormat:@"%d", (long)[selectDate timeIntervalSince1970]];
        }else {
//            self.endTime = [NSString stringWithFormat:@"%d", (long)[selectDate timeIntervalSince1970]];
            self.endTimeLbl.text = date;
             self.endTime= [selectDate stringWithFormat:@"yyyyMMdd"];
        }
    }];
    datepicker.dateLabelColor = RGB(65, 188, 241);//年-月-日-时-分 颜色
    datepicker.datePickerColor = [UIColor blackColor];//滚轮日期颜色
    datepicker.doneButtonColor = RGB(65, 188, 241);//确定按钮的颜色
    datepicker.yearLabelColor = [UIColor clearColor];//大号年份字体颜色
    [datepicker show];
}

- (MonitorViewModel *)monitorViewModel
{
    if (_monitorViewModel == nil) {
        _monitorViewModel = [[MonitorViewModel alloc] init];
    }
    
    return _monitorViewModel;
}

- (StatisticViewModel *)stisticViewModel
{
    if (_stisticViewModel == nil) {
        _stisticViewModel = [[StatisticViewModel alloc] init];
    }
    
    return _stisticViewModel;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark - 查询
- (IBAction)searchBtnClick:(UIButton *)sender {
    StatisticViewController *statistic = [self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-2];
    statistic.isFromSearchView = YES;
    statistic.startTime = self.startTime;
    statistic.endTime = self.endTime;
    statistic.associateLength=2;
    statistic.loadingType=1;
    [self.navigationController popToViewController:statistic animated:YES];
}

#pragma mark - 选择开始日期
- (IBAction)startDate:(UIButton *)sender {
    [self showTimeSelect:YES];
}

#pragma mark - 选择结束日期
- (IBAction)endDate:(UIButton *)sender {
    [self showTimeSelect:NO];
}
@end
